<div id="main-form">

	<? if($message > 0){ ?>
		<div id="message_box">
			<p class="img"></p>
			<p class="txt">
				<? if($message == 1){
						echo "You have successfully added a new user .";
					}elseif($message == 2){
						echo "You have successfully updated user.";
					}
				?>
			</p>
		</div>

	<? }else{ ?>

		<form name="submitForm" id="submitForm" method="POST" action="<?=$_SERVER['REQUEST_URI']?>">
			<input type="hidden" name="id" id="id" value="<?=$user_id?>">
			<input type="hidden" name="user_id" id="user_id" value="<?=$user_id?>">
			
			<ul class="main-two-cols">
				<li class="two-cols-left">
					<h2 class="singlerow">LOGIN DETAILS</h2>
					<ul class="rows">
						<li class="leftcol">Username</li>
						<li class="rightcol">
							<input type="text" name="username" id="username" value="<?=$user_row['username']?>">
						</li>
					</ul>
					<ul class="rows">
						<li class="leftcol">Password</li>
						<li class="rightcol">
							<input type="text" name="password" id="password" <?=$disable_password?> >
							<?if(!empty($user_id)){?>
								<p class="form-note"> 
									<a href="javascript:void(0);" onclick="enablePassword()">Change Password</a>
								</p>
							<? } ?>
						</li>
					</ul>
					<ul class="rows">
						<li class="leftcol">User Category</li>
						<li class="rightcol"><?=$user_type_select?></li>
					</ul>
					<?if(!empty($user_id) && $user_row['user_type_id'] == CONST_SUPER_ADMIN_TYPE){?>
						<input type="hidden" name="is_practicioner" value="0">
					<? } else {?>
						<ul class="rows">
							<li class="leftcol">User Role</li>
							<li class="rightcol">
								<input type="radio" name="is_practicioner" value="1" onclick="showPracticionerForm()" <?=($user_row['is_practicioner'] == 1)?'checked':''?> > Practicioner 
								<input type="radio" name="is_practicioner" value="0" onclick="showNonPracticionerForm()" <?=($user_row['is_practicioner'] == 0)?'checked':''?> > Non-Practicioner 
							</li>
						</ul>
					<? } ?>
				</li>
				<li class="two-cols-right">
					<ul class="rows">
						<li class="leftcol">&nbsp;</li>
						<li class="rightcol">&nbsp;</li>
					</ul>
					<ul class="rows">
						<li class="leftcol">&nbsp;</li>
						<li class="rightcol">&nbsp;</li>
					</ul>
					<ul class="rows">
						<li class="leftcol">User Group</li>
						<li class="rightcol">
							<?php
								if($_SESSION['user']['user_type_id'] == CONST_SUPER_ADMIN_TYPE){
									echo $group_select;
								}else{
									echo $_SESSION['user']['group_name'];
									echo "<input type='hidden' name='group_id' id='group_id' value='".$_SESSION['user']['group_id']."'>";
								}
							?>
						</li>
					</ul>
					<ul class="singleColRows">
						<li class="leftcol">Status</li>
						<li class="rightcol">
							<input type="radio" name="active" value="1" <?=(!empty($user_id) && $user_row['active'] == 1)?'checked':'';?> > Active 
							<input type="radio" name="active" value="0" <?=(!empty($user_id) && $user_row['active'] == 0)?'checked':'';?> > Inactive
						</li>
					</ul>
				</li>
			</ul>

			<br clear="all" />
			<div id="ajax-user"></div>

			<p class="buttons_elements">
				<input type="submit" class="form-button btn" id="submitBtn" value="Save">
				<input type="button" class="form-button btn" id="cancelBtn" value="Cancel">
			</p>
			<br clear="all" />
		</form>

	<? } ?>
</div>

<script type="text/javascript">
	function showPracticionerForm(){
		$("#ajax-user").load("practicioner&id=<?=$user_id?>");
	}
	function showNonPracticionerForm(){
		$("#ajax-user").load("nonpracticioner&id=<?=$user_id?>");
	}
	function enablePassword(){
		$("#password").removeAttr("disabled");
	}
	
	$(document).ready(function() {
		var role = $('input[name=is_practicioner]:checked').val();
		if(role == 1){
			showPracticionerForm();
		}else{
			showNonPracticionerForm();
		}
	});
</script>